home *** CD-ROM | disk | FTP | other *** search
/ PC Open 97 / PC Open 97 CD2.bin / Demo / FileMaker / Data1.cab / simple_table.xsl4 < prev    next >
Encoding:
Extensible Markup Language  |  2002-05-24  |  3.8 KB  |  111 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult" exclude-result-prefixes="fmp">
  3.     <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
  4. <!--
  5. File: simple_table.xsl
  6.  
  7. Transforms data exported in the FMPXMLRESULT grammar into an 
  8. HTML table. 
  9.  
  10. ===============================================================
  11.  
  12. Copyright ┬⌐ 2002 FileMaker, Inc.
  13. All rights reserved.
  14.  
  15. Redistribution and use in source and binary forms, with or
  16. without modification, are permitted provided that the following
  17. conditions are met:
  18.  
  19. * Redistributions of source code must retain the above copyright
  20.   notice, this list of conditions and the following disclaimer.
  21.  
  22. * Redistributions in binary form must reproduce the above copyright
  23.   notice, this list of conditions and the following disclaimer in 
  24.   the documentation and/or other materials provided with the
  25.   distribution.
  26.  
  27. * Neither the name of the FileMaker, Inc. nor the names of its 
  28.   contributors may be used to endorse or promote products derived
  29.   from this software without specific prior written
  30.   permission.
  31.  
  32. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  35. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
  36. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
  37. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
  38. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  39. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  40. BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  41. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  42. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  43. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44.     
  45. ===============================================================
  46. -->
  47. <!--
  48. Template: match="fmp:FMPXMLRESULT"
  49.  
  50. The main driver for building the table. Calls the header template then iterates through
  51.  the RESULTSET nodeset to build the table rows.
  52. -->
  53.     <xsl:template match="fmp:FMPXMLRESULT">
  54.         <html>
  55.             <body>
  56.                 <table border="1" cellPadding="1" cellSpacing="1">
  57.                     <xsl:call-template name="header"/>
  58.                     <xsl:for-each select="fmp:RESULTSET/fmp:ROW">
  59.                         <tr>
  60.                             <xsl:for-each select="fmp:COL">
  61.                                 <td>
  62.                                     <xsl:value-of select="fmp:DATA"/>
  63.                                 </td>
  64.                             </xsl:for-each>
  65.                         </tr>
  66.                     </xsl:for-each>
  67.                 </table>
  68.             </body>
  69.         </html>
  70.     </xsl:template>
  71. <!--
  72. Template: header
  73.  
  74. Creates the heading for the HTML table. The database name and number of records
  75. are displayed above the field names.
  76. -->
  77.     <xsl:template name="header">
  78.         <tr>
  79.             <td align="middle">
  80.                 <xsl:attribute name="colspan"><xsl:call-template name="numfields"/></xsl:attribute>
  81.                 <xsl:text>Database: </xsl:text>
  82.                 <xsl:value-of select="fmp:DATABASE/@NAME"/>
  83.             </td>
  84.         </tr>
  85.         <tr>
  86.             <td align="middle">
  87.                 <xsl:attribute name="colspan"><xsl:call-template name="numfields"/></xsl:attribute>
  88.                 <xsl:text>Records: </xsl:text>
  89.                 <xsl:value-of select="fmp:DATABASE/@RECORDS"/>
  90.             </td>
  91.         </tr>
  92.         <tr>
  93.             <xsl:for-each select="fmp:METADATA/fmp:FIELD">
  94.                 <td align="middle">
  95.                     <xsl:value-of select="@NAME"/>
  96.                 </td>
  97.             </xsl:for-each>
  98.         </tr>
  99.     </xsl:template>
  100. <!--
  101. Template: numfields
  102.  
  103. Simple utility template that checks for the number of children in the METADATA
  104. element and returns the number of fields in the database - handy when building
  105. tables.
  106. -->
  107.     <xsl:template name="numfields" match="fmp:METADATA">
  108.         <xsl:value-of select="count(fmp:METADATA/child::*)"/>
  109.     </xsl:template>
  110. </xsl:stylesheet>
  111.